package com.sun.designpatternsdemo.visitor

import android.util.Log

/**
 * 版权：xx公司 版权所有
 * @author sun
 * 版本：1.0
 * 创建日期：2021/7/1 17:18
 * 描述：类
 *
 */
interface ComputerPart{
    fun accept(computerPartVisitor: ComputerPartVisitor)
}
interface ComputerPartVisitor{
    fun visit(computer: Computer)

    fun visit(mouse: Mouse)

    fun visit(keyboard: Keyboard)

    fun visit(monitor: Monitor)
}

class ComputerPartDisplayVisitor:ComputerPartVisitor{
    override fun visit(computer: Computer) {
        Log.e("---", "Displaying Computer.")
    }

    override fun visit(mouse: Mouse) {
            Log.e("---", "Displaying Mouse.")
    }

    override fun visit(keyboard: Keyboard) {
        Log.e("---", "Displaying Keyboard.")
    }

    override fun visit(monitor: Monitor) {
        Log.e("---", "Displaying Monitor.")
    }

}

class Computer:ComputerPart{
    private val parts = arrayOf(
        Mouse(),Keyboard(),Monitor()
    )
    override fun accept(computerPartVisitor: ComputerPartVisitor) {
        for (part in parts){
            part.accept(computerPartVisitor)
        }
        computerPartVisitor.visit(this)
    }

}

class Keyboard:ComputerPart{
    override fun accept(computerPartVisitor: ComputerPartVisitor) {
       computerPartVisitor.visit(this)
    }
}
class Monitor:ComputerPart{
    override fun accept(computerPartVisitor: ComputerPartVisitor) {
        computerPartVisitor.visit(this)
    }
}

class Mouse:ComputerPart{
    override fun accept(computerPartVisitor: ComputerPartVisitor) {
        computerPartVisitor.visit(this)
    }

}
